package com.javabase.y2022.m05.day0516.v04;

/**
 * @descriptions: 使用數組實現棧
 * @author: Tom
 * @date: 2022/5/16 下午 01:37
 * @version: 1.0
 */
public class Solution {
    public static class MyStack02{
        int size;
        int index;
        int[] arr;
        int capacity;
        public MyStack02(int size){
            this.capacity = size;
            this.size = 0;
            this.arr = new int[size];
            this.index = this.size - 1;
        }
        public  void push(int value){
            if(this.size == this.capacity){
                throw new RuntimeException("size is full.");
            }
            arr[this.index] = value;
            this.size++;
            this.index--;
        }
        public int pop(){
            if(this.size == 0){
                throw new RuntimeException("size is empty");
            }
            int ans = this.arr[this.index++];
            return ans;
        }

    }

}
